package com.gt.admin.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.gt.common.annotation.Log;
import com.gt.common.core.controller.BaseController;
import com.gt.common.core.domain.AjaxResult;
import com.gt.common.enums.BusinessType;
import com.gt.admin.domain.QuestionnaireDetail;
import com.gt.admin.service.IQuestionnaireDetailService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 筛查问卷具体资料controller
 */
@Api(tags = "sc-筛查问卷具体资料")
@RestController
@RequestMapping("/screening-questionnaire/detail")
public class QuestionnaireDetailController extends BaseController {
    @Autowired
    private IQuestionnaireDetailService questionnaireDetailService;

    /**
     * 根据上级目录id查询资料
     */
    @ApiOperation("根据上级目录id查询资料")
    @GetMapping("/{superId}")
    public AjaxResult getById(@PathVariable("superId") Long superId){
        LambdaQueryWrapper<QuestionnaireDetail> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.eq(QuestionnaireDetail::getSuperId, superId);
        return AjaxResult.success(questionnaireDetailService.list(queryWrapper));
    }

    /**
     * 新增具体资料
     */
    @ApiOperation("新增具体资料")
    @Log(title = "问卷资料", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult insert(@RequestBody QuestionnaireDetail questionnaireDetail){
        return toAjax(questionnaireDetailService.save(questionnaireDetail));
    }

    /**
     * 修改具体资料
     */
    @ApiOperation("修改具体资料")
    @Log(title = "问卷资料", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult update(@RequestBody QuestionnaireDetail questionnaireDetail){
        return toAjax(questionnaireDetailService.updateById(questionnaireDetail));
    }

    /**
     * 删除具体资料
     */
    @ApiOperation("删除具体资料")
    @Log(title = "问卷资料", businessType = BusinessType.DELETE)
    @DeleteMapping("/{id}")
    public AjaxResult delete(@PathVariable("id")Long id){
        return toAjax(questionnaireDetailService.removeById(id));
    }
}
